//                       注册页面（js/jq + 正则）
window.onload = function(){
	// 手机号码验证：
	var otel = document.getElementById("tel");
	otel.onfocus = function(){
		var ospan = this.nextSibling; // tel的相邻兄弟即span
		ospan.innerHTML = "请填写正确的11位手机号码并进行验证";
		ospan.className = "remind";
	}
	otel.onblur = function(){
		var value = otel.value;
		var ospan = this.nextSibling;
		if(value){
			if(/^1[3,5,7]\d{9}$/.test(value)){
				ospan.innerHTML = "";
				ospan.className = "success";
			}else{
				ospan.innerHTML = "手机号码格式错误，请重新填写";
				ospan.className = "error";
			}
		}else{
			ospan.innerHTML = "";
		}
	}
	// 密码验证：
	var opwd1 = document.getElementById("pwd1");
	opwd1.onfocus = function(){
		var ospan = this.nextSibling;
		ospan.innerHTML = "请填写6到12位密码，可使用数字和字母组合";
		ospan.className = "remind";
	}
	opwd1.onblur = function(){
		var ospan = this.nextSibling;
		var pwd1 = opwd1.value;
		if(pwd1){
			if(/^\w{6,20}$/.test(pwd1)){
				ospan.innerHTML = "";
				ospan.className = "success"
			}else{
				ospan.innerHTML = "格式错误，请输入6到20位字符，字母加数字或下划线的组合";
				ospan.className = "error"
			}
		}else{
			ospan.innerHTML = "";
		}
	}
	// 确认密码：
	var opwd2 = document.getElementById("pwd2");
	opwd2.onfocus = function(){
		var ospan = this.nextSibling;
		ospan.innerHTML = "请您再次输入密码";
		ospan.className = "remind";
	}
	opwd2.onblur = function(){
		var ospan = this.nextSibling;
		var pwd2 = this.value;
		var pwd1 = opwd1.value;
		if(pwd2){
			if(pwd2 == pwd1){
				ospan.innerHTML = "";
				ospan.className = "success";
			}else{
				ospan.innerHTML = "两次输入密码不一致，请重新输入";
				ospan.className = "error";
			}
		}else{
			ospan.innerHTML = "";
		}
	}
	// 验证码：
	var overify = document.getElementById("verify");
	// 数字机组合验证码：
	function verify(){
		var str = "abcdefghijkmnpqrstuvwxyz23456789ABCDEFGHJKLMNPQRSTUVWXYZ";
		var l = str.length;
		var stra = parseInt(Math.random()*l);
		var strb = parseInt(Math.random()*l);
		var strc = parseInt(Math.random()*l);
		var strd = parseInt(Math.random()*l);
		 verifystr = str[stra] + str[strb] + str[strc] + str[strd];	
		return verifystr;
	}
	overify.innerHTML = verify();
	overify.onclick = function(){
		overify.innerHTML = verify();
		return false;
	}
	// 验证：
	var otext = document.getElementById("text-verify");
	otext.onfocus = function(){
		var ospan = this.nextSibling.nextSibling;
		ospan.innerHTML = "请输入验证码";
		ospan.className = "remind";
	}
	otext.onblur = function(){
		var ospan = this.nextSibling.nextSibling;
		var content = this.value;
		if(content){
			if(content.toLowerCase() == overify.innerHTML.toLowerCase()){
				ospan.innerHTML = "";
				ospan.className = "success";
			}else{
				ospan.innerHTML = "验证码输入有误，请重新输入";
				ospan.className = "error";
			}
		}else{
			ospan.innerHTML = "";
		}
	}
	// 提交注册：jq
	$("#submit").click(function(){
		var $textver = $("#text-verify").val();
		var $spanvar = $("#verify").html();
		if(/^1[3,5,7]\d{9}$/.test( $("#tel").val()) && /^\w{6,20}$/.test( $("#pwd1").val() ) && $("#pwd2").val() == $("#pwd1").val() &&  $("#text-verify").val().toLowerCase() == $("#verify").html().toLowerCase()){
			console.log("success");
			setCookie("username",tel.value,10);
			setCookie("password",pwd1.value,10);
			location.replace("loading.html");
		}else{
			alert("请填写正确信息");
			$("#tel").focus();
		}
	})
	
	
// 二级菜单显隐：
$(".all-btn").hover(
	function(){
		$(".submenu").css("display","block");
		$(".thrmenu").css({"display":"none"});
		$(".all-btn").css("cursor","pointer");
	},
	function(){
		$(".submenu").css("display","none");
	}
);
// 三级菜单显隐：
var $olis = $(".submenu li" );
$olis.each(function(){
	$(this).hover(function(){		
		$(".thrmenu").css({"display":"block","box-shadow":"0 0 4px #666"})
		$olis.css("box-shadow","none");
		$(this).css({"box-shadow":"0 0 4px #666","padding":"0 15px"})
	},
	function(){
		$(".thrmenu").css("display","none");
	})
})

	
}

